//   Copyright 2012,2013 Vaughn Vernon
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package com.saasovation.agilepm.domain.model.product;

import com.saasovation.agilepm.domain.model.ValueObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

import java.util.Locale;

/**
 * @值对象：产品ID
 */
public class ProductId extends ValueObject {

    @Autowired
    MessageSource messageSource;

    private Locale locale;
    /**
     * 作为身份标识的ID
     */
    private String id;

    /**
     * 由指定ＩＤ构造产品ID
     *
     * @param anId ID
     */
    public ProductId(String anId) {
        // 调用私有构造器
        this();

        // 设置身份标识ID
        this.setId(anId);
    }

    /**
     * 由产品ID构造新产品ＩＤ
     *
     * @param aProductId
     */
    public ProductId(ProductId aProductId) {
        // 调用指定ＩＤ生成产品ＩＤ
        this(aProductId.id());
    }

    /**
     * 私有默认构造器
     */
    private ProductId() {
        // 调用父类构造器
        super();
    }

    /**
     * 获取身份标识ID
     *
     * @return 返回身份标识ID
     */
    public String id() {
        return this.id;
    }

    /**
     * 设置产品ID的身份标识ID
     *
     * @param anId 身份标识ID
     */
    private void setId(String anId) {
        this.id = anId;
    }

    /**
     * 相等逻辑覆盖
     *
     * @param anObject 比较对象
     * @return 是否相等
     */
    @Override
    public boolean equals(Object anObject) {
        boolean equalObjects = false;

        // 和比较对象判断相等的逻辑如下：
        // 不为空 且 类相同的情况下，属性ID也想同表示相等
        if (anObject != null && this.getClass() == anObject.getClass()) {
            ProductId typedObject = (ProductId) anObject;
            equalObjects = this.id().equals(typedObject.id());
        }

        return equalObjects;
    }

    /**
     * hashCode逻辑覆盖
     *
     * @return 返回hashCode值
     */
    @Override
    public int hashCode() {
        int hashCodeValue =
                +(57853 * 31)
                        + this.id().hashCode();

        return hashCodeValue;
    }

    /**
     * 获取产品ＩＤ的字符串值
     *
     * @return　定制化的返回字符串
     */
    @Override
    public String toString() {
        return "ProductId [id=" + id + "]";
    }


}
